//
//  ViewController.swift
//  淡出淡入动画
//
//  Created by app on 2017/4/14.
//  Copyright © 2017年 app. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    var loginButton:UIButton!
    override func viewDidLoad() {
        super.viewDidLoad()
        
        loginButton = UIButton()
        loginButton.frame  = CGRect(x: 20, y: 230, width: view.frame.width - 40, height: 40)
        loginButton.backgroundColor = UIColor.red
        loginButton.setTitle("11", for: .normal)
        view.addSubview(loginButton)
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        // 淡出淡入动画
//        let animation:CABasicAnimation = CABasicAnimation()
//        animation.keyPath = "opacity"
//        animation.fromValue = UIColor.green.cgColor
//        animation.toValue = 1.0
//        animation.duration = 2.0
//        animation.fillMode = kCAFillModeForwards
//        animation.isRemovedOnCompletion = false
//        loginButton?.layer.add(animation, forKey: nil)
        
        // 阴影渐变
        loginButton.layer.shadowColor = UIColor.red.cgColor
        loginButton.layer.shadowOpacity = 0.5
        
        let animation = CABasicAnimation()
        animation.keyPath = "shadowOffset"
        animation.toValue = NSValue(cgSize: CGSize(width: 10, height: 10))
        animation.duration = 2
        animation.fillMode = kCAFillModeForwards
        loginButton.layer.add(animation, forKey: nil)
    }
}

